<?php
//redis 类
class myRedis{
    protected $redis;
    protected $host='127.0.0.1';
    protected $port=6379;
    //初始化时传参选择多少号数据库
    public function __construct($dbcount=0){
        $this->redis = new Redis();
        $this->redis->connect($this->host, $this->port);
        //选择数据库
        $this->redis->select($dbcount);
    }
    /**
     *写入缓存
     */
    public function set($key,$value){
        return $this->redis->set($key,$value);
    }
    /**
     *获取缓存数据
     */
    public function get($key){
        return $this->redis->get($key);
    }
    /**
     *检查key是否存在
     */
    public function exists($key){
        return $this->redis->exists($key);
    }
    /**
     *设置键过期时间
     */
    public function expire($key,$second){
        return $this->redis->expire($key,$second);
    }
    /**
     *获取key的生命时间
     */
    public function ttl($key){
        return $this->redis->ttl($key);
    }
}